<?php

/**
 * sfValidatorDatePage validates date parts. 
 * It also converts the input value to a valid date.
 *
 * @package    flexiwik
 * @subpackage validator
 * @author     Jonathan Olger Nieto Lajo <jonathan_nieto@hotmail.com>
 */
class sfValidatorExtendedPartialDate extends sfValidatorDate
{
  protected function doClean($value)
  {
    if (
         ($value['day']   && !$value['year'])
         ||
         ($value['month'] && !$value['year'])
         ||
         ($value['day']   && !$value['month'])
       )
    {
      throw new sfValidatorError($this, 'invalid', array('value' => $value));
    }
    
    $value['day']   = $value['day']   ? $value['day']   : '00';
    $value['month'] = $value['month'] ? $value['month'] : '00';

    return sfDateFormatExt::encodeExtendedDate($value);
  }
}
